﻿using Microsoft.AspNetCore.Builder;
using NetAutoGUI;
using System.Diagnostics;
using System.Net.Http.Headers;
using System.Text;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Tab;

//if (GUI.Application.IsApplicationRunning("WeChat"))
//{
//    var win = GUI.Application.FindWindowByTitle("微信");

//    win.Activate();
//    //win.Maximize();

//    Thread.Sleep(1000);

//    GUI.Keyboard.Write("傻屌啊");
//    GUI.Keyboard.KeyDown(VirtualKeyCode.RETURN);
//}




namespace Test.NetAuto;

public  class Program
{

    static readonly HttpClient client = new HttpClient();

    [STAThread]
    private static async Task Main(string[] args)
    {

        //bool IsRun=true;
        //while (IsRun)
        //{
        //    var read = Console.ReadLine();
        //    if (read == "ofd")
        //    {
        //        OpenFileDialog ofd = new OpenFileDialog();
        //        var aaa = ofd.ShowDialog();
        //        if (aaa == DialogResult.OK)
        //        {
        //            Console.WriteLine(ofd.FileName);
        //        }
        //    }

        //    if (read=="exit")
        //    {
        //        IsRun = false;
        //    }

        //    Thread.Sleep(10);
        //}

        //Console.WriteLine(  "程序停止");

        //try
        //{
        //    // 设置请求URL
        //    string url = "https://luckycola.com.cn/tools/sensiWords";

        //    // 创建JSON格式的请求体
        //    var content = new FormUrlEncodedContent(new[]
        //    {
        //            new KeyValuePair<string, string>("ColaKey", "WxJk1c6YDL82xO1704953175520G2aMPPHbWq"),
        //            new KeyValuePair<string, string>("wordStr", "我艹"),
        //            new KeyValuePair<string, string>("isStrict", "0")
        //        });
        //    content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
        //    string requestBody = await content.ReadAsStringAsync();
        //    //Console.WriteLine(requestBody); // 打印请求体以供调试，实际开发中应移除此行代码
        //    var response=await client.PostAsync(url, content);
        //    string responseBody = await response.Content.ReadAsStringAsync();
        //    Console.WriteLine(responseBody);
        //}
        //catch (Exception ex)
        //{
        //    // 异常处理逻辑，打印异常信息到控制台
        //    Console.WriteLine($"Exception: {ex.Message}");
        //}

        // 创建请求体
        var content = new StringContent(CreateJsonBody(), Encoding.UTF8);
        content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");

        // 发送POST请求并获取响应
        HttpResponseMessage response = await client.PostAsync(url, content);
        response.EnsureSuccessStatusCode();

        // 获取响应数据并输出到控制台
        string responseBody = await response.Content.ReadAsStringAsync();
        Console.WriteLine(responseBody);
    }

    static string url = "https://luckycola.com.cn/ai/openwxyy";
    static string appKey = "659f856dc7c5dfb046890dcf";
    static string ques = "今天是星期几？";
    static string uid = "t2SHxZ1704953175520467aTuoXpF";

    // 将请求体JSON化
    private static string CreateJsonBody()
    {
        var jsonBuilder = new StringBuilder();
        jsonBuilder.Append("{");
        jsonBuilder.Append($"\"appKey\":\"{appKey}\","); // appKey参数值需要替换为实际值
        jsonBuilder.Append($"\"ques\":\"{ques}\","); // ques参数值需要替换为实际值
        jsonBuilder.Append($"\"uid\":\"{uid}\","); // uid参数值需要替换为实际值
        jsonBuilder.Append($"\"isLongChat\":\"0\""); // uid参数值需要替换为实际值
        jsonBuilder.Append("}"); // uid参数值需要替换为实际值
        return jsonBuilder.ToString();
    }
}